package test.propertyTester;

import org.eclipse.core.internal.propertytester.ResourcePropertyTester;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.internal.Workbench;

@SuppressWarnings("restriction")
public class MyPropTester extends ResourcePropertyTester {

	@Override
	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {

		ISelectionService selectionService = Workbench.getInstance()
				.getActiveWorkbenchWindow().getSelectionService();

		ISelection selection = selectionService.getSelection();

		if (selection instanceof IStructuredSelection) {
			Object element = ((IStructuredSelection) selection)
					.getFirstElement();

			IProject project;
			if (element instanceof IResource) {
				IResource res = (IResource) element;

				project = res.getProject();

				System.out.println("Project class name="
						+ project.getClass().getName());

				try {
					System.out
							.println("Project has android nature="
									+ project
											.hasNature("com.android.ide.eclipse.adt.AndroidNature"));

					if (project
							.hasNature("com.android.ide.eclipse.adt.AndroidNature")) {
						return true;

					}

				} catch (CoreException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				/*
				 * String activeProjectName = project.getName(); if
				 * (activeProjectName.equals("Test Ground")) { return true; }
				 */

			}
		}

		// TODO Auto-generated method stub
		return false;
	}

}
